package com.lc.question.pojo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

@ApiModel("分页实体类")
public class PageBean <T>{

	//1.当前页的页码
	@ApiModelProperty("当前页的页码")
	private int currentPage;
	//2.每页显示的记录个数
	@ApiModelProperty("每页显示的记录个数")
	private int pageCount;
	//3.记录的总数
	@ApiModelProperty("记录的总数")
	private long totalCount;
	//4.页码的总数
	@ApiModelProperty("页码的总数")
	private long totalPage;
	//5.每一页记录的起始位置(下标)
	@ApiModelProperty("每一页记录的起始位置(下标)")
	private int startIndex;
	//6.当前页的数据集
	@ApiModelProperty("当前页的数据集")
	private List<T> pageDate;
	//7.显示页的最小页码
	@ApiModelProperty("显示页的最小页码")
	private long start;
	//8.显示页的最大页码
	@ApiModelProperty("显示页的最大页码")
	private long end;
	
	
	
	//定义构造方法
	public PageBean(int currentPage,int pageCount,long totalCount) {
		this.currentPage=currentPage;
		this.pageCount=pageCount;
		this.totalCount=totalCount;
		
		//计算总页数
		totalPage=(totalCount%pageCount==0) ? totalCount/pageCount : totalCount/pageCount+1;
		
		//给每一页的第一条记录赋值(下标)
		startIndex=(currentPage-1)*pageCount;
		
		//给显示页的起始位置和结束位置赋值。
		start=1;
		end=5;
		//讨论一下总页码不够5页时的处理,和超过5页时的处理
		if(this.totalPage<=5) {
			this.end=this.totalPage;
		}else {
			this.start=this.currentPage-2;
			this.end=this.currentPage+2;
			//判断极端情况
			if(start<1) {
				this.start=1;
				this.end=5;
			}
			if(end>totalPage) {
				this.end=totalPage;
				this.start=this.end-4;
			}
		}	
	}



	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	
	
	public int getPageCount() {
		return pageCount;
	}
	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	
	public long getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(long totalCount) {
		this.totalCount = totalCount;
	}

	
	public long getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(long totalPage) {
		this.totalPage = totalPage;
	}

	
	public int getStartIndex() {
		return startIndex;
	}
	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

	
	public List<T> getPageDate() {
		return pageDate;
	}
	public void setPageDate(List<T> pageDate) {
		this.pageDate = pageDate;
	}

	
	public long getStart() {
		return start;
	}
	public void setStart(long start) {
		this.start = start;
	}

	
	public long getEnd() {
		return end;
	}
	public void setEnd(long end) {
		this.end = end;
	}
	
}
